#include "process.h"    
#include <unistd.h>    
#include <time.h>    
#include <stdlib.h>    
    
// 函数指针类型    
typedef void (*call_t)(const char*,double,double);    
    
double total = 1024.0;    
//double speed = 1.0;    
double speed[] = {1.0, 0.5, 0.3, 0.2, 0.1, 0.01};    
    
// 回调函数    
void download(double total,call_t cb)    
{    
    srand(time(NULL));    
    double current = 0.0;    
    while(current<=total)    
    {    
        cb("下 载 中",total,current);
        if(current==total) break;
        int random = rand()%6;    
        usleep(5000);    
        current += speed[random];
        if(current>=total){
            current = total;
        }
    }        
    printf("\n");    
}    
    
void upload(double total,call_t cb)    
{    
    srand(time(NULL));    
    double current = 0.0;    
    while(current<=total)    
    {
        cb("上 传 中",total,current);
        if(current==total) break;
        int random = rand()%6;    
        usleep(5000);    
        current += speed[random];
        if(current>=total){
            current = total;
        }
    }
    printf("\n");
}
int main()
{
    download(1024.0,FlushProcess);
    printf("download 1024.0MB done\n");
    download(512.0,FlushProcess);
    printf("download 512.0MB done\n");
    download(256.0,FlushProcess);
    printf("download 256.0MB done\n");
    download(128.0,FlushProcess);
    printf("download 128.0MB done\n");
    download(64.0,FlushProcess);
    printf("download 64.0MB done\n");

    upload(500.0,FlushProcess);
    printf("upload 500.0MB done\n");
    //process();
    return 0;
}
